package springboot.demo.controller;

import com.netflix.discovery.DiscoveryClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import springboot.demo.dao.NovelMapper;
import springboot.demo.service.Provider;

@RestController
public class DemoController {

	@Autowired
	NovelMapper novelDao;

	@Autowired
	Provider provider;

	private static Logger LOGGER = LoggerFactory.getLogger(DemoController.class);
	
	@GetMapping("/v1/hello")
	public String get() {
		DiscoveryClient d;
		LOGGER.info("Hello spring");
		return "Hello spring";
	}

	@GetMapping("/v1/novel/{id}")
	public String queryNovel(@PathVariable("id") int id){
		LOGGER.info("consumer");
		return provider.queryNovelById(id);
	}

	@GetMapping("/v1/novelName/{id}")
	public String queryNovelById(@PathVariable("id") int id){
		LOGGER.info("provider");
		return novelDao.selectByPrimaryKey(id).getNovelName();
	}

}
